package com.df.bpm.utils.businessViewerV2.business;

import com.df.bpm.utils.businessViewerV2.res.V_scrollPanel;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class V_scroll4BusinessGroup extends V_scrollPanel<Integer> {

    V_businessByOutput baba;

    public V_scroll4BusinessGroup(V_businessByOutput baba){
        this.baba=baba;
        this.putModel(null);
    }

    @Override
    public List<String> getColNames() {
        return Arrays.asList("分组");
    }

    @Override
    public void hideCol(JTable iTable) {
//        Main.hideCol(iTable,0);
    }

    @Override
    public List<Integer> colWidthSetting() {
        return new ArrayList<>(Arrays.asList(3));
    }

    @Override
    public Object[] getRowValues(Integer row) {
        return new Object[]{row};
    }

    @Override
    public Integer getEmptyRow() {
        return null;
    }

    @Override
    public MouseListener mouseAdapter4Table(JTable iTable, List<Integer> list) {
        return new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int row = iTable.rowAtPoint(e.getPoint());
                int col = iTable.columnAtPoint(e.getPoint());
                if (row >= 0 ) {
                    if (e.getClickCount() == 2) {// 处理双击事件
                        if(col==0){// 查询业务详情
                            Integer group=list.get(row);
                            if(group==null){
                                group=newGroup(list);
                                iTable.setValueAt(group, row, col);
                            }
                            baba.setActiveGroup(group);
                        }
                    }
                }
            }
        };
    }

    private Integer newGroup(List<Integer> list) {
        int result=1;
        while(list.contains(result)){
            result+=1;
        }
        return result;
    }

}
